(function (vc, vm) {

    vc.extends({
        data: {
            editIntegralInfo: {
                detailType: '',
                integralName: '',
                integralId: '',
                amount: '',
                value:'',
                link: '',
                remark:'',

            }
        },
        _initMethod: function () {

        },
        _initEvent: function () {
            vc.on('editIntegral', 'openEditIntegralModal', function (_params) {
                $that.refreshEditIntegralInfo();
                $('#editIntegralModel').modal('show');
                vc.copyObject(_params, $that.editIntegralInfo);
            });
        },
        methods: {
            editIntegralValidate: function () {
                return vc.validate.validate({
                    editIntegralInfo: $that.editIntegralInfo
                }, {
                    'editIntegralInfo.value': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "数量不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "10",
                            errInfo: "数量不能超过10位"
                        },
                    ],

                    'editIntegralInfo.integralId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "编号不能为空"
                        }]
                });
            },
            editIntegral: function () {
                if (!$that.editIntegralValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }

                vc.http.apiPost(
                    '/integral.changeIntegralAmount',
                    JSON.stringify($that.editIntegralInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editIntegralModel').modal('hide');
                            vc.emit('userIntegral', 'listIntegral', {});
                            vc.emit('storeIntegral', 'listIntegral', {});
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');

                        vc.toast(errInfo);
                    });
            },
            refreshEditIntegralInfo: function () {
                $that.editIntegralInfo = {
                    detailType: '',
                    integralName: '',
                    integralId: '',
                    amount: '',
                    link: '',
                    value:'',
                    remark:'',
                }
            }
        }
    });

})(window.vc, window.$that);
